package a66weding.com.jiehuntong.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.widget.FrameLayout;

import com.baidu.mapapi.map.MapView;

import java.util.HashMap;
import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.application.GlobalApplication;
import a66weding.com.jiehuntong.beans.WedRegistryMapBean;
import a66weding.com.jiehuntong.fragment.BaseToolsDayPlanFragment;
import a66weding.com.jiehuntong.fragment.Tools_WedRegLocationFragment;
import a66weding.com.jiehuntong.fragment.Tools_WedRegMainFragment;
import a66weding.com.jiehuntong.fragment.Tools_WedReg_CityFragment;
import a66weding.com.jiehuntong.widgets.quicksearchlist.CityData;
import a66weding.com.jiehuntong.widgets.quicksearchlist.ContactItemInterface;

/**
 * @version :
 * @creator : AxDu
 * @create-time : 2016/6/3
 * @description :
 */
public class ToolsWedRegisterActivity extends FragmentActivity  {
    private FrameLayout mContentLay;
    private BaseToolsDayPlanFragment mFragment;
    private FragmentManager fragmentManager;
    private Bundle mMainBundle;
    private MapView mMapView;

    private String cityName="北京";

    private HashMap<String,BaseToolsDayPlanFragment> mDayPlanPages;

    List<ContactItemInterface> contactList;

    private WedRegistryMapBean mCurrentMapBean;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tools_wedreg_fragmentactivity);
        ((GlobalApplication)getApplication()).getActivityManager().addActivity("ToolsDayPlanActivity",this);
        mDayPlanPages = new HashMap<String,BaseToolsDayPlanFragment>();
        mDayPlanPages.put("登记处主页",new Tools_WedRegMainFragment());
        mDayPlanPages.put("城市选择",new Tools_WedReg_CityFragment());
        mDayPlanPages.put("选择地点",new Tools_WedRegLocationFragment());
        initview();

        initData();


    }

    private void initData() {
        contactList=  CityData.getSampleContactList();

    }


    private void initview() {
        mContentLay = (FrameLayout) findViewById(R.id.flay_tools_wedregcontent);

        setFragment("登记处主页");
    }





    /**
     * 设置 Fragment 到布局中
     */
    public  void setFragment(String pagerName) {
        fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();

        mFragment=mDayPlanPages.get(pagerName);

        mMainBundle = new Bundle();
        mMainBundle.putString("pagerName",pagerName);

        mFragment.setArguments(mMainBundle);

        transaction.addToBackStack(pagerName);

        transaction.replace(R.id.flay_tools_wedregcontent, mFragment);

        transaction.commit();

    }

    @Override
    protected void onResume() {
        super.onResume();
        if(mMapView!=null) {
            mMapView.onResume();
        }
    }



    @Override
    protected void onPause() {
        if(mMapView!=null) {
            mMapView.onPause();
        }
        super.onPause();
    }

    @Override
    protected void onDestroy() {
       if(mMapView!=null) {
           mMapView.onDestroy();
           mMapView=null;
       }

        super.onDestroy();
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        super.onKeyDown(keyCode, event);
        if(keyCode == KeyEvent.KEYCODE_BACK){
            if(getSupportFragmentManager().getBackStackEntryCount()==1){
                finish();
                return true;
            }
        }
        return super.onKeyUp(keyCode,event);
    }


    public WedRegistryMapBean getmCurrentMapBean() {
        return mCurrentMapBean;
    }

    public void setmCurrentMapBean(WedRegistryMapBean mCurrentMapBean) {
        this.mCurrentMapBean = mCurrentMapBean;
    }


    public List<ContactItemInterface> getContactList() {
        return contactList;
    }

    public void setContactList(List<ContactItemInterface> contactList) {
        this.contactList = contactList;
    }

    public MapView getmMapView() {
        return mMapView;
    }

    public void setmMapView(MapView mMapView) {
        this.mMapView = mMapView;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

}
